package com.gukun.springboot.tdengine.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gukun.springboot.tdengine.domain.common.CommonResult;
import com.gukun.springboot.tdengine.domain.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author zhang
 */
@RestControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(value = ServiceException.class)
    public CommonResult<?> serviceException(ServiceException e) {
        log.error(e.getMessage(),e);
        return CommonResult.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(value = RuntimeException.class)
    public CommonResult<?> runtimeException(RuntimeException e) {
        log.error(e.getMessage(),e);
        return CommonResult.error(500,e.getMessage());
    }
}
